package pers.zb.cloud.service.upms.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import pers.zb.cloud.service.upms.service.UserService;
import pers.zb.cloud.service.upms.vo.JsonResult;
import pers.zb.cloud.service.upms.vo.UserAuthoritiesInfoVo;

/**
 * 用户服务
 */
@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据登录账户名获取用户信息、权限
     *      目前该方法只提供给OAuth系统使用（项目名称 sea-cloud-oauth），对应的业务代码请查看 pers.zb.cloud.oauth.support.CustomizeUserDetailsService
     */
    @RequestMapping(value = "/authorities/info/{account}",produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public JsonResult<UserAuthoritiesInfoVo> getUserInfoAndPermissionDetail(@PathVariable("account") String loginAccount) throws Exception {
        log.debug("根据用户登录名获取用户信息，参数loginAccount - {}",loginAccount);
        UserAuthoritiesInfoVo userInfoVo = userService.getUserInfoAndPermissionDetail(loginAccount);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setResult(userInfoVo);
        return jsonResult;
    }
}
